package br.mil.aer.pame.aniversariantes;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.liferay.util.mail.MailEngine;

public class AniversariantesPortlet extends MVCPortlet {

	@Override
	public void processAction(ActionRequest actionRequest,
			ActionResponse actionResponse) throws IOException, PortletException {
		// TODO Auto-generated method stub
		super.processAction(actionRequest, actionResponse);
		String userId = actionRequest.getRemoteUser();
		User user;
		try {
			user = UserLocalServiceUtil.getUserById(Long.parseLong(userId));
			String from = user.getEmailAddress();
			String to = actionRequest.getParameter("mailTo");
			String subject="Feliz Aniversário";
			String body = actionRequest.getParameter("mensagem");
			
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		MailEngine.send(from, to, subject, body);
		
	}

}
